# -*- coding: utf-8 -*-
"""
@Time ： 2021/8/6 20:48
@Auth ： Mr.掌心 2929184523
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：请输入模块功能描述
"""
#app cwaler 谷歌官方的自动化遍历工具
#
import os
import threading
import time

from appium import webdriver

appium_path = r"D:\Appium"
appium_path += r"\resources\app\node_modules\appium\build\lib\main.js"

def func_child(appium_path):
    """
    定义一个函数，专门处理阻塞业务
    :param appium_path: appium路径
    :return:
    """
    #当我们启动appium服务器的时候，阻塞主线程
    os.system("node " + appium_path)

#创建一个子线程
#target,子线程需要处理的函数名
th = threading.Thread(target=func_child, args=(appium_path,))
th.start()
time.sleep(5)


caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "127.0.0.1:7555"
caps["platformVersion"] = "6.0.1"
caps["appPackage"] = "com.tencent.mobileqq"
caps["appActivity"] = ".activity.SplashActivity"
caps["ensureWebviewsHavePages"] = True

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
driver.implicitly_wait(15)
el1 = driver.find_element_by_accessibility_id("同意")
el1.click()
el2 = driver.find_element_by_id("com.tencent.mobileqq:id/btn_login")
el2.click()
el3 = driver.find_element_by_accessibility_id("请输入QQ号码或手机或邮箱")
el3.send_keys("2929184523")
el4 = driver.find_element_by_accessibility_id("密码 安全")
el4.send_keys("testing123")
el5 = driver.find_element_by_accessibility_id("登 录")
el5.click()
el6 = driver.find_element_by_accessibility_id("去授权按钮")
el6.click()
el7 = driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button")
el7.click()
el8 = driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button")
el8.click()

driver.quit()